﻿#region
using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using ZhongLangDB;
#endregion

namespace ZHONGLANGWEBUI.ZHONGLANG.SYS
{
    public partial class MENU : TT_BasePageList
    {
        protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pageInit(); dgListDo("查询初次", ""); } }

        #region pageInit
        protected override void pageInit()
        {

        }
        #endregion

        #region pageBind 
        protected DataTable proSDListQuery(int iType)
        {
            SortedList SDList = new SortedList();
            SDList["MENUID"] = txtQMENUID.Text;
            SDList["MENUNAME"] = txtQMENUNAME.Text;
            DataTable dt = pgShow.proQueryData(SDList, "PROTT_SYS_MENUQUERY", iType);
            return dt;
        }

        protected override void pageBind()
        {
            DataTable dt = proSDListQuery(1);
            DataView dv = dt.DefaultView;
            if (ViewState["SortExpression"] != null) { dv.Sort = GetSortDirectiont(ViewState["SortExpression"].ToString(), ViewState["SortDirection"].ToString()); }
            dgList.DataSource = dv; dgList.DataBind();
        }
        #endregion

        #region pageOpt 
        protected override void dgListDo(string strCommandName, string strCommandArgument)
        {
            #region dgBase 
            if (strCommandName == "查询初次") { pgShow.CurrPageIndex = 1; pgShow.CurrPageSize = REQPAGECOUNT; pageBind(); }
            if (strCommandName == "查询") { pageBind(); }
            if (strCommandName == "导出") { proExpData(proSDListQuery(2), dgList); }
            #endregion

            #region 修改
            if (strCommandName == "修改" || strCommandName == "批量修改")
            {
                string strBack = "";
                foreach (GridViewRow gr in dgList.Rows)
                {
                    string strKeyID = dgList.DataKeys[gr.RowIndex]["MENUID"].ToString();
                    if ((strKeyID == strCommandArgument && strCommandName == "修改")
                        || (((CheckBox)(gr.FindControl("ckID"))).Checked && strCommandName == "批量修改"))
                    {
                        SortedList SDList = new SortedList();
                        SDList["KEYID"] = strKeyID;
                        SDList["MENUNAME"] = ((TextBox)(gr.FindControl("txtEMENUNAME"))).Text;
                        SDList["PAGECOUNT"] = ((TextBox)(gr.FindControl("txtEPAGECOUNT"))).Text;
                        SDList["MENUORDER"] = ((TextBox)(gr.FindControl("txtEMENUORDER"))).Text;
                        SDList["MENUIMGCSS"] = ((TextBox)(gr.FindControl("txtEMENUIMGCSS"))).Text;
                        SDList["UPDATEMANID"] = CURREMP.USERID; SDList["UPDATEMANNAME"] = CURREMP.USERNAME;
                        strBack = DBPark.proSetDB(SDList, "PROTT_SYS_MENUSAVE");
                        if (strCommandName == "修改") { break; }
                    }
                }
                if (strBack != "" && strBack.Substring(0, 2) != "OK") { jsMessage(strBack); }
                else { pageBind(); }
            }
            #endregion  
        }
        #endregion 
    }
}